<?php
/**
 * Manageaccount_Data_Updateusercompanydata
 * update user company data
 * @author Adrian Stolarski
 */
class Manageaccount_Data_Updateusercompanydata implements Manageaccount_Data_Mainable, 
        Manageaccount_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * update main user company data
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action = new Manageaccount_Data_Redirectmanageaccount;
        $this->redirect_action->main($variables);
    }
    
    /**
     * prapare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database_query = "UPDATE "
                . "user_company_data"
                . " SET "
                . "company_name='".$variables['company_name'].
                "', "
                . "company_tax_identification_number='"
                .$variables['company_tax_identification_number'].
                "', "
                . "company_regon_number='"
                .$variables['company_regon'].
                "', "
                . "company_street='"
                .$variables['company_street'].
                "', "
                . "company_local_number='"
                .$variables['company_local_number'].
                "', "
                . "company_postal_code='"
                .$variables['company_postal_code'].
                "', "
                . "company_city='"
                .$variables['company_city'].
                "', "
                . "company_email='"
                .$variables['company_email'].
                "', "
                . "company_telephone_number='"
                .$variables['company_telephone_number'].
                "', "
                . "company_fax_number='"
                .$variables['company_fax_number'].
                "'"
                . " WHERE "
                . "company_user_id="
                .$variables['user_id'].
                ";";
        //echo $this->database_query;
        //die();
    }

}
